#include "stdio.h"

int shu[151],n;

int check(int a)
{
	int i,j,tt[151];
	int k,num,step,n_1;
	memcpy(tt,shu,sizeof(shu));
	tt[1]=1;
	num=1;
	n_1=n-1;
	k=1;
	while (num<n_1)
	{
		
		for (j=1;j<=a;++j)
		{
			++k;
			if (k>n) k=1;
			while (tt[k]==1) 
			{
				++k;
				if (k>n) k=2;
			}
		}
		if (k==2) return 0;
		tt[k]=1;	
		++num;
	}
	return 1;
	
}


main()
{
	int i,j;
	

	scanf("%d",&n);
	while (n!=0)
	{
	memset(shu,0,sizeof(shu));
	for (i=2;;++i)
	{
		if (check(i)==1)
		{
			printf("%d\n",i);
			break;
		}
	}
	scanf("%d",&n);
	}	

	
}
